<template>
  <el-dialog v-else :visible.sync="pay">
    <span class="balance">
      <el-button @click="payByBalance"><div class="el-icon-wallet">通过账户余额付款</div></el-button>

    </span>
    <span class="alipay">
      <el-avatar :src="require('@/assets/alipay.png')"></el-avatar>
      <el-button class="alipay" @click="payByAlipay">通过支付宝付款</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {alipay, pay_by_balance} from "@/api/pay";

export default {
  props: {gameId: {type: Number, required: true}, pay: {type: Boolean, required: true}},
  methods: {
    payByBalance() {
      pay_by_balance(this.$store.getters.getToken, this.game.id).then(response => {
        let code = response.data.code;
        if (code == 200) {
          this.operate_show = false;
          location.reload();
        } else if (code == 501) {
          this.$alert('您已经购买了该游戏')
          this.operate_show = false;
          location.reload();
        }
      })
    },
    payByAlipay() {
      alipay(this.$store.getters.getToken, this.game.id, this.game.name, 1, this.game.discountPrice ? this.game.discountPrice : this.game.price).then(response => {
        console.log(response)
      })
    },
  }
}
</script>

<style>

</style>